#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog)
{
    ui->setupUi(this);
    filename=new QLabel("文件路径名称：",this);
    name=new QLineEdit(this);
    openfile=new QPushButton("打开文件...",this);
    QGridLayout* gly=new QGridLayout(this);
    connect(openfile,&QPushButton::clicked,this,[this](){
        QString filepath=QString(QFileDialog::getOpenFileName(this,"打开文件对话框","/","files(*)"));
        name->setText(filepath);});
    filesize=new QLabel("文件容量大小：",this);
    fs=new QLineEdit(this);

    createfiletime=new QLabel("文件创建时间：",this);
    cft=new QLineEdit(this);

    modifiletime=new QLabel("最后修改时间：",this);
    mft=new QLineEdit(this);

    openfiletime=new QLabel("最后访问时间：",this);
    oft=new QLineEdit(this);

    fileattribute=new QLabel("文件属性：",this);

    gly->addWidget(filename,0,0);
    gly->addWidget(name,0,1);
    gly->addWidget(openfile,0,2);

    gly->addWidget(filesize,1,0);
    gly->addWidget(fs,1,1,1,2);

    gly->addWidget(createfiletime,2,0);
    gly->addWidget(cft,2,1,1,2);

    gly->addWidget(modifiletime,3,0);
    gly->addWidget(mft,3,1,1,2);

    gly->addWidget(openfiletime,4,0);
    gly->addWidget(oft,4,1,1,2);

    gly->addWidget(fileattribute,5,0,1,2);

    file=new QCheckBox("文件",this);
    hide=new QCheckBox("隐藏属性",this);
    onlyread=new QCheckBox("只读权限",this);
    onlywrite=new QCheckBox("只写权限",this);
    exc=new QCheckBox("执行权限",this);
    QHBoxLayout* hly=new QHBoxLayout(this);
    hly->addWidget(file);
    hly->addWidget(hide);
    hly->addWidget(onlyread);
    hly->addWidget(onlywrite);
    hly->addWidget(exc);
    QVBoxLayout* vly=new QVBoxLayout(this);

    gly->addLayout(hly,6,0,1,2);


    btn=new QPushButton("获取文件属性全部数据信息",this);
    connect(btn,&QPushButton::clicked,this,&Dialog::getatrribute);
    gly->addWidget(btn,7,0,1,2);

    vly->addLayout(gly);
    this->setLayout(vly);
    resize(600,400);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::getatrribute()
{   QFileInfo fileinfo(name->text());
    fs->setText(QString::number(fileinfo.size()));
    cft->setText(fileinfo.birthTime().toString());
    mft->setText(fileinfo.lastModified().toString());
    oft->setText(fileinfo.lastRead().toString());

     bool bfile=fileinfo.isFile();
     bool bhide=fileinfo.isHidden();
     bool bread=fileinfo.isReadable();
     bool bwrite=fileinfo.isWritable();
     bool bexecute=fileinfo.isExecutable();
     file->setCheckState(bfile?Qt::Checked:Qt::Unchecked);
     hide->setCheckState(bhide?Qt::Checked:Qt::Unchecked);
     onlyread->setCheckState(bread?Qt::Checked:Qt::Unchecked);
     onlywrite->setCheckState(bwrite?Qt::Checked:Qt::Unchecked);
     exc->setCheckState(bexecute?Qt::Checked:Qt::Unchecked);




}

